<?php

namespace App\Http\Controllers\Captcha;

use App\Constants\ResponseArray;
use App\Http\Controllers\BaseController;
use App\Http\Services\CaptchaService;
use Illuminate\Http\Request;

class CaptchaController extends BaseController
{

    /**
     * verify 验证码
     * @param Request $request
     * @return array
     */
    public function captchaVerify(Request $request)
    {
        $data = $request->all();
        $rules = [
            // 验证码参数
            'captchaVerifyParam' => 'required|string',
            // 业务参数
            'bizParam' => 'nullable',
        ];
        $result = $this->validator($data, $rules, []);
        if ($result) {
            return ResponseArray::parameterError($result, $rules);
        }

        $res = CaptchaService::captchaVerify($data['captchaVerifyParam']);

        if (!empty($res['statusCode']) && $res['statusCode'] == 200)
        {
            if (!empty($res['body']['Result']['VerifyResult']))
            {
                return ResponseArray::response($res['body']['Result']['VerifyResult'],$res['body']['Result']['Message'] ?? '');
            }
        }

        return ResponseArray::abortMessage($res['body']['Result']['Message'] ?? '');
    }

}
